package com.guli.cart.web;

import com.guli.cart.service.CartService;
import com.guli.cart.vo.CartItemVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

/**
 * @author: 朱财艺
 * @date : 2022/02/09
 * @Description:
 */
@Controller
public class CartController {

    @Autowired
    private CartService cartService;

    @RequestMapping(value = {"/"})
    public String cartList(Model model){


        return "cartList";
    }

    @RequestMapping("success")
    public String success(){

        return "success";
    }

    @RequestMapping("/addToCart")
    public String addToCart(@RequestParam("skuId")Long skuId,
                            @RequestParam("num")Integer num,
                            Model model
                            ){

        CartItemVo cartItemVo = cartService.addToCart(skuId, num);

        model.addAttribute("item",cartItemVo);

        return "success";
    }
}
